<% layout('/layouts/default.html', {title: '应付单查询', libs: ['validate','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text('应付单详情')}
				<% if (tap.status1 != "5" && hasPermi('payment:tap:cancel')){ %>
				<a href="javascript:void(0);" id="zuofei"
				   class="btn btn-primary" title="${text('作废')}"
				   data-layer="true" data-layer-width="400" data-layer-height="200"
				> ${text('作废')}</a>
				<% } %>

				<% if (tap.billStatus == "2" && hasPermi('payment:tap:approve')){ %>
				<a href="javascript:void(0);" id="tongguo"
				   class="btn btn-primary" title="${text('通过')}"
				   data-layer="true" data-layer-width="400" data-layer-height="200"
				> ${text('通过')}</a>
				<% } %>

				<% if (tap.billStatus == "2" && hasPermi('payment:tap:approve')){ %>
				<a href="javascript:void(0);" id="jujue"
				   class="btn btn-primary" title="${text('拒绝')}"
				   data-layer="true" data-layer-width="400" data-layer-height="200"
				> ${text('拒绝')}</a>
				<% } %>

				<% if ((tap.billStatus == "1"||tap.billStatus == "4") && hasPermi('payment:tap:edit')){ %>
				<a href="javascript:void(0);" id="tijiao"
				   class="btn btn-primary" title="${text('提交')}"
				   data-layer="true" data-layer-width="400" data-layer-height="200"
				> ${text('提交')}</a>
				<% } %>
				<% if ((tap.status1 == "2" || tap.status1 == "3") && hasPermi('payment:tap:pay')){ %>
				<a href="${ctx}/pay/tpayment/form?apId=${tap.apId}" id="btnFinancial1"
				   class="btn btn-primary addTabPage" title="${text('新增付款单')}"
				> ${text('付款')}</a>
				<% } %>
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${tap}" action="${ctx}/payment/tap/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="apId"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="apCode" maxlength="100" class="form-control" disabled="true" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('供应商')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="supplierId" items="${supplierList}" itemLabel="supplierName" itemValue="supplierId"
								class="form-control required" blankOption="true" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="date" readonly="true" maxlength="20" class="form-control required" disabled="true"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('单据状态')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="status1" dictType="payment_bill_type" class="form-control" blankOption="true" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('审批状态')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="billStatus" dictType="finance_bill_status" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('服务订单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="serviceOrderId" items="${serviceOrderList}" itemLabel="serviceOrderCode" itemValue="serviceOrderId"
								class="form-control required" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('付款账号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="paymentAccount" maxlength="100" class="form-control" disabled="true" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('金额')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="amount" maxlength="100" class="form-control" disabled="true" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('币种')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="currency" dictType="sys_bizhongy" class="form-control" blankOption="true" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('前置单据类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="parentBillType" dictType="erp_record_type" blankOption="true" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('前置单据编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="parentBillCode1" dictType=""  class="form-control"  readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('应付单明细')}</h4>
				<div class="ml10 mr10">
					<table id="tapDetailDataGrid"></table>
				</div>
			</div>

		<div class="form-unit">${text('系统信息')}</div>
		<div class="row">
			<div class="col-xs-6">
				<div class="form-group">
					<label class="control-label col-sm-4" title="">
						<span class="required hide">*</span> ${text('创建者')}：<i class="fa icon-question hide"></i></label>
					<div class="col-sm-8">
						<#form:input path="createBy" maxlength="64" class="form-control " readonly="true"/>
					</div>
				</div>
			</div>
			<div class="col-xs-6">
				<div class="form-group">
					<label class="control-label col-sm-4" title="">
						<span class="required hide">*</span> ${text('创建时间')}：<i class="fa icon-question hide"></i></label>
					<div class="col-sm-8">
						<#form:input path="createDate" readonly="true" maxlength="20" class="form-control "
						dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
					</div>
				</div>
			</div>
			<div class="col-xs-6">
				<div class="form-group">
					<label class="control-label col-sm-4" title="">
						<span class="required hide">*</span> ${text('更新者')}：<i class="fa icon-question hide"></i></label>
					<div class="col-sm-8">
						<#form:input path="updateBy" maxlength="64" class="form-control " readonly="true"/>
					</div>
				</div>
			</div>
			<div class="col-xs-6">
				<div class="form-group">
					<label class="control-label col-sm-4" title="">
						<span class="required hide">*</span> ${text('更新时间')}：<i class="fa icon-question hide"></i></label>
					<div class="col-sm-8">
						<#form:input path="updateDate" class="form-control " readonly="true"
						dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
					</div>
				</div>
			</div>
		</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
//初始化应付单明细DataGrid对象
$("#tapDetailDataGrid").dataGrid({

	data: ${toJson(tap.tapDetailList)},
	datatype: "local", // 设置本地数据
	showFooter: true,	//显示底部合计
	autoGridHeight: function(){return 'auto'}, // 设置自动高度

	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'apDetailId', editable:true, hidden:true},
		{header:'${text("行号")}', name:'rowNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'20', 'class':'form-control','readonly':'true'}},
		{header:'${text("品牌")}', name:'brand', width:150, editable:true, edittype:'select', editoptions:{'maxlength':'20', 'class':'form-control','readonly':'true',
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('car_pinpai')}),
				itemLabel: 'dictLabel', itemValue: 'dictValue'
			}},
		{header:'${text("版型")}', name:'area', width:150, editable:true, edittype:'select', editoptions:{'maxlength':'64', 'class':'form-control','readonly':'true',
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('car_quyu')}),
				itemLabel: 'dictLabel', itemValue: 'dictValue'
			}},
		{header:'${text("车型")}', name:'model', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control','readonly':'true'}},
		{header:'${text("车辆")}', name:'car.carName', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'64', 'class':'form-control','readonly':'true'}},
		{header:'${text("车")}', name:'carId', width:150, editable:true, hidden:true, edittype:'text', editoptions:{'maxlength':'64', 'class':'form-control','readonly':'true'}},
		{header:'${text("车架号")}', name:'frameNumber', width:150,editable:true, edittype:'text', editoptions:{'maxlength':'100','class':'form-control','readonly':'true'}},
		{header:'${text("费用项目")}', name:'expenseItemName', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control','readonly':'true'}},
		{header:'${text("项目")}', name:'expenseItem', width:150, editable:true, edittype:'text', hidden:true, editoptions:{'class':'form-control','readonly':'true'}},
		{header:'${text("应付金额")}', name:'apAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number','readonly':'true'}},
		{header:'${text("实付金额")}', name:'actualApAmount', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number','readonly':'true'}},
		{header:'${text("备注")}', name:'remarik', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'255', 'class':'form-control','readonly':'true'}},
		{header:'${text("应付单ID")}', name:'apId.apId', editable:true, hidden:true},
		{header:'${text("操作")}', name:'actions', hidden: true}
	],

	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#tapDetailDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {apDetailId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

	// 编辑表格的提交数据参数
	editGridInputFormListName: 'tapDetailList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,apDetailId,brand,area,model,carId,frameNumber,expenseItem,apAmount,actualApAmount,remarik,apId.apId,rowNumber', // 提交数据列表的属性字段

	// 加载成功后执行事件
	ajaxSuccess: function(data){
		// 设置底部合计行数据(设置合计行)

		$('#tapDetailDataGrid').dataGrid("footerData", "set", {
			'apAmount' : '${tap.totalAmount}'
		}, false);
	}
});
</script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
$(function () {
	var billId = "${tap.parentBillCode}";
	var billCode = "${tap.parentBillCode1}";
	var option = $("<option>").attr({
		"value": billId
	}).text(billCode);
	$("#parentBillCode1").append(option);
	$("#parentBillCode1 parentBillCode1:first").prop("selected", 'selected');
	$("#parentBillCode1").change();
	//通过
	$("#tongguo").click(function () {
		$.ajax({
			type: "post",
			url: "${ctx}/payment/tap/updateFinancialRecognition?apId=${tap.apId}&sta=3",
			success: function(data){
				js.confirm(data,function () {
					location.reload(true)
				})
			}
		});
	})

	//提交
	$("#tijiao").click(function () {
		$.ajax({
			type: "post",
			url: "${ctx}/payment/tap/updateFinancialRecognition?apId=${tap.apId}&sta=2",
			success: function(data){
				js.confirm(data,function () {
					location.reload(true)
				})
			}
		});
	})

	//拒绝
	$("#jujue").click(function () {
		$.ajax({
			type: "post",
			url: "${ctx}/payment/tap/updateFinancialRecognition?apId=${tap.apId}&sta=4",
			success: function(data){
				js.confirm(data,function () {
					location.reload(true)
				})
			}
		});
	})

	//作废
	$("#zuofei").click(function () {
		$.ajax({
			type: "post",
			url: "${ctx}/payment/tap/updateFinancialRecognition?apId=${tap.apId}&sta=5",
			success: function(data){
				js.confirm(data,function () {
					location.reload(true)
				})
			}
		});
	})
})
</script>
